Cookie Consent: Add configurable geo provider#49998
Conversation
Summary: - Normalize cookie consent config into nested features and geo groups while preserving legacy top-level geo aliases for existing filters. - Gate geo cache-cookie filtering and frontend geo config emission on features.geo, and update the frontend resolver to consume geo provider settings. - Document the custom geo endpoint contract and add helper coverage for nested geo config and configured region lists. Rationale: - Consumers need to replace the WPCOM geo endpoint and regulated-region lists without forking the package. - Keeping resolution client-side and only ignoring resolved geo cookies when geo is enabled preserves the existing cache-safety behavior. Tests: - mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent test - mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent typecheck - mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent build - mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent exec eslint src/modules/cookie-consent/utils.ts src/modules/cookie-consent/view.ts tests/utils.test.ts - composer php:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php - composer phpcs:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php - composer phpcs:compatibility -- projects/packages/cookie-consent/src/class-cookie-consent.php - vendor/bin/phan --allow-polyfill-parser --include-analysis-file-list projects/packages/cookie-consent/src/class-cookie-consent.php --no-progress-bar
Summary: - Always register the Boost ignore-cookies callback and re-check geo config inside the callback so late config filters are respected. - Prefer explicit nested geo schema values over changed legacy aliases when both are present. - Remove redundant geo enablement from the README custom-provider example and add a focused disabled-geo snippet. Rationale: - Runtime geo checks avoid an init-time filter ordering constraint for consumers that disable geo through the config filter. - Nested geo config is the current schema, so it should not be silently overridden by legacy aliases during partial migrations. Tests: - composer php:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php - composer phpcs:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php - composer phpcs:compatibility -- projects/packages/cookie-consent/src/class-cookie-consent.php - vendor/bin/phan --allow-polyfill-parser --include-analysis-file-list projects/packages/cookie-consent/src/class-cookie-consent.php --no-progress-bar
Summary: - Treat nested geo key presence as authoritative when resolving legacy alias conflicts, including explicit default values. - Use nullish fallback for the frontend geo provider and default geo lists for fallback parity with sibling fields. Rationale: - Consumers using the current nested schema should not have explicit nested intent overridden by older flat aliases. - Consistent fallback semantics reduce surprises if provider values evolve. Tests: - composer php:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php - composer phpcs:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php - composer phpcs:compatibility -- projects/packages/cookie-consent/src/class-cookie-consent.php - vendor/bin/phan --allow-polyfill-parser --include-analysis-file-list projects/packages/cookie-consent/src/class-cookie-consent.php --no-progress-bar - mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent test - mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent typecheck - mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent exec eslint src/modules/cookie-consent/utils.ts src/modules/cookie-consent/view.ts tests/utils.test.ts - mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent build
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 🔴 Action required: Please add missing changelog entries for the following projects: Use the Jetpack CLI tool to generate changelog entries by running the following command: Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Boost plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Premium Analytics plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
There was a problem hiding this comment.
Pull request overview
This PR expands the Cookie Consent package configuration schema to support a configurable geo provider (defaulting to WPCOM), including a nested features.geo flag to disable geo resolution entirely, while preserving legacy flat geo config keys via normalization.
Changes:
- Add
features.geoand nestedgeo.*configuration with legacy key aliasing and normalization (PHP + JS helpers). - Update the Interactivity store to gate geo resolution, cookie reads/writes, and region-based consent logic on
features.geo. - Document the new config schema and custom geo provider contract; add unit tests for geo config helpers.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| projects/packages/cookie-consent/tests/utils.test.ts | Adds unit tests for geo config helpers and precedence rules. |
| projects/packages/cookie-consent/src/modules/cookie-consent/view.ts | Gates geo initialization/usage on features.geo and switches to getGeoConfig()-derived settings. |
| projects/packages/cookie-consent/src/modules/cookie-consent/utils.ts | Introduces geo config helpers and updates GDPR/CCPA matching to use normalized geo config. |
| projects/packages/cookie-consent/src/class-cookie-consent.php | Adds normalized nested geo config (plus legacy aliases), and only ignores geo cookies in Boost cache when geo is enabled. |
| projects/packages/cookie-consent/README.md | Documents the new config schema, custom provider contract, and disabled-geo behavior. |
| projects/packages/cookie-consent/changelog/add-configurable-geo-provider | Adds changelog entry for configurable geo provider/settings. |
Normalize configured GDPR country lists to uppercase and CCPA region lists to lowercase in both PHP config normalization and frontend geo config helpers. Add JS and PHP coverage for nested geo lists and legacy aliases. Reviewer-comment-ids: 3480368909, 3480368933
Avoid PHP 8.5 ReflectionMethod::setAccessible() deprecations in the config normalization tests and satisfy Phan's null-coalescing rule in Cookie Consent config normalization. Review comments: 3480368909, 3480368933
Summary: - Merge current trunk into the Cookie Consent geo provider branch. - Resolve the Cookie Consent config conflict by keeping the nested geo provider normalization and adding trunk's configurable copy defaults to the same normalized config path. - Include trunk's .agents updates in the commit tree without rewriting the read-only workspace copies. Rationale: - The PR branch was conflicting with trunk after adjacent Cookie Consent copy configurability and consent-log changes landed. - Combining copy and geo normalization preserves both public config APIs and keeps frontend config emission gated by features.geo. Tests: - composer php:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php - mise exec node@24.15.0 -- pnpm jetpack test php packages/cookie-consent - mise exec node@24.15.0 -- pnpm jetpack test js packages/cookie-consent (skipped: No test-js script in composer.json) - vendor/bin/phan --allow-polyfill-parser --include-analysis-file-list projects/packages/cookie-consent/src/class-cookie-consent.php --no-progress-bar - composer phpcs:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php - composer phpcs:compatibility -- projects/packages/cookie-consent/src/class-cookie-consent.php - git diff --check - git diff --cached --check
| Are you an Automattician? The PR will need to be tested on WordPress.com. This comment will be updated with testing instructions as soon the build is complete. |
|
Symphony AI is leaving this unchanged because this is the standard PR metadata reminder and the only remaining item shown is adding a |
Fixes WOOA7S-1600
Proposed changes
features.geoandgeo.*Cookie Consent config, with WPCOM as the default provider.geo.*keys authoritative.Related product discussion/links
Does this pull request change what data or activity we track or use?
No new tracking events or tracked properties. This changes Cookie Consent geo source configuration and region-selection behavior.
Testing instructions
git diff --name-only origin/trunk...HEAD.mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent test.mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent typecheck.mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent build.mise exec node@24.15.0 -- pnpm --filter @automattic/jetpack-cookie-consent exec eslint src/modules/cookie-consent/utils.ts src/modules/cookie-consent/view.ts tests/utils.test.ts.composer php:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php.composer phpcs:lint -- projects/packages/cookie-consent/src/class-cookie-consent.php.composer phpcs:compatibility -- projects/packages/cookie-consent/src/class-cookie-consent.php.vendor/bin/phan --allow-polyfill-parser --include-analysis-file-list projects/packages/cookie-consent/src/class-cookie-consent.php --no-progress-bar.